﻿#include "pch.h"
#include "AtCodeMaster.h"
#include "afxdialogex.h"
#include "CameraList.h"
#include "AtCodeMasterDlg.h" 
#include "tinyxml2.h"                       //xml文件读写

IMPLEMENT_DYNAMIC(DeviceList, CDialogEx)

DeviceList::DeviceList(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DeviceList, pParent)
{ 
}

DeviceList::~DeviceList()
{
}

void DeviceList::DoDataExchange(CDataExchange* pDX)
{ 
    DDX_Control(pDX, IDC_EDIT1_CameraListHik0, EditHik0);
    DDX_Control(pDX, IDC_EDIT1_CameraListHik1, EditHik1);
    DDX_Control(pDX, IDC_EDIT1_CameraListDh1, EditDh1);
    DDX_Control(pDX, IDC_EDIT1_CameraListZw0, EditZw0);
    DDX_Control(pDX, IDC_LIST0, Hik0.List);
    DDX_Control(pDX, IDC_LIST1, Hik1.List);
    DDX_Control(pDX, IDC_DaHuaLIST0, Dh1.List);
    DDX_Control(pDX, IDC_ZhongWeiList0, Zw0.List); 
	CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(DeviceList, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_BN_CLICKED(IDC_Camera0, &DeviceList::BnClickedCamera0)
    ON_BN_CLICKED(IDC_Camera1, &DeviceList::BnClickedCamera1)
    ON_BN_CLICKED(IDC_DaHuaCamera0, &DeviceList::OnBnClickedDahuacamera0) 
    ON_BN_CLICKED(IDC_CameraIpConfigs, &DeviceList::OnBnClickedCameraipconfigs) 
    ON_BN_CLICKED(IDC_ZhongWeiCamera0, &DeviceList::OnBnClickedZhongweicamera0) 
    ON_EN_KILLFOCUS(IDC_EDIT1_CameraListHik0, &DeviceList::OnEnKillfocusEdit1Cameralisthik0)
    ON_EN_KILLFOCUS(IDC_EDIT1_CameraListHik1, &DeviceList::OnEnKillfocusEdit1Cameralisthik1)
    ON_EN_KILLFOCUS(IDC_EDIT1_CameraListDh1, &DeviceList::OnEnKillfocusEdit1Cameralistdh1)
    ON_EN_KILLFOCUS(IDC_EDIT1_CameraListZw0, &DeviceList::OnEnKillfocusEdit1Cameralistzw0)
    ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &DeviceList::OnNMDblclkList1)
    ON_NOTIFY(NM_DBLCLK, IDC_LIST0, &DeviceList::OnNMDblclkList0)
    ON_NOTIFY(NM_DBLCLK, IDC_ZhongWeiList0, &DeviceList::OnNMDblclkZhongweilist0)
END_MESSAGE_MAP()

//华睿相机搜索
typedef  std::map<std::string, VslbCameraInfos> cameraInfoMapTypeList;//相机信息列表
cameraInfoMapTypeList gCameraInfoMapTypeList;
void* h_HuaRui[MaxDeviceNum]{ NULL };      //华睿设备句柄 
UINT8 HuaRuiNum = 0;
VslbCameraInfosArray* onCameraInfosArray = new VslbCameraInfosArray;     //华睿相机信息列表     
//访问窗体类
DeviceList* p_DevListDlg = NULL; 
/***********1 包裹包裹所有相机信息回调函数**************/
/*回调信息中，包含所有相机的扫码信息及图片信息；包裹的汇总条码信息和时间戳信息，可根据时间戳信息匹配对应包裹的主回调信息，实现包裹业务信息的绑定（ps：包裹条码为noread时，存储对应的所有相机图片信息）*/
int __stdcall onListAllCameraCodeInfoC(const AllCameraCodeInfo* allCameraInfo)
{
    DeviceList* pThis = (DeviceList*)p_DevListDlg;
    if (pThis)
    {
        pThis->ListAllCameraCodeInfoC(allCameraInfo);
        return 0;
    }
}
void DeviceList::ListAllCameraCodeInfoC(const AllCameraCodeInfo* allCameraInfo)
{
    CListCtrl* DaHua1List = (CListCtrl*)GetDlgItem(IDC_DaHuaLIST0);
    for (int i = 0; i < allCameraInfo->numCam; i++)
    { 
        CString ip = Oth.ChToCStr(allCameraInfo->cameraCodeInfo[i].cameraIP); //获取当前行的IP 
        CString mac;    //获取当前行的MAC
        CString netip;  //获取当前行的网口Ip 
        DaHua1List->InsertItem(0, ip);         //列表显示-IP      
        DaHua1List->SetItemText(0, 4, mac);    //列表显示-Mac     
        DaHua1List->SetItemText(0, 5, netip);  //列表显示-网口IP  
    }
}
//主回调信息处理回调函数
void __stdcall onRunResultCList(const char* key, const VslbRunResult* results)
{
    DeviceList* pThis = (DeviceList*)p_DevListDlg;
    if (pThis)
    {
        pThis->ListRunResultC(key, results);
    }
}
// 主回调信息处理  
void  DeviceList::ListRunResultC(const char* key, const VslbRunResult* results)
{ 
    cameraInfoMapTypeList::iterator ite = gCameraInfoMapTypeList.find(std::string(key));	//根据相机key值获取相机的其他信息
    if (ite != gCameraInfoMapTypeList.end())
    {
        VslbCameraInfos cameraInfo = ite->second; 
    } 
} 
//正在绘制控件
HBRUSH DeviceList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    if(ListOne == FALSE)
    {
        ListOne = TRUE;
        RECT  m_rect;
        GetConfig(); 
        //工业相机 
        Hik0.List.ModifyStyle(0, ~LVS_TYPEMASK & LVS_EDITLABELS | LVS_REPORT, 0);
        Hik0.List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB | LVS_EX_DOUBLEBUFFER | LVS_EX_CHECKBOXES);  
        Hik0.List.InsertColumn(0, L"供包台ID", LVCFMT_LEFT, 60);//表头：1索引，2内容，3对齐方式，4宽度 
        Hik0.List.InsertColumn(1, L"设备IP",   LVCFMT_LEFT, 100);
        Hik0.List.InsertColumn(2, L"型号",     LVCFMT_LEFT, 80);
        Hik0.List.InsertColumn(3, L"版本号",   LVCFMT_LEFT, 80);
        Hik0.List.InsertColumn(4, L"序列号",   LVCFMT_LEFT, 90);
        Hik0.List.InsertColumn(5, L"物理地址", LVCFMT_LEFT, 90);
        Hik0.List.InsertColumn(6, L"网口IP",   LVCFMT_LEFT, 100);
        for (int8_t i = Hik0.CheckNum - 1; i >= 0; --i)
        {
            if (Hik0.Check[i] == false)continue; //if (Hik0.Number[i] == "")continue;
            std::wstring wstrFeedId = std::to_wstring(Hik0.FeedId[i]);
            LPCWSTR lpFeedId = wstrFeedId.c_str();
            Hik0.List.InsertItem(0, lpFeedId);               //列表显示 
            Hik0.List.SetItemText(0, 1, Hik0.Ip[i]);         //列表显示
            Hik0.List.SetItemText(0, 2, Hik0.Name  [i]);     //列表显示
            Hik0.List.SetItemText(0, 3, Hik0.Ves   [i]);     //列表显示
            Hik0.List.SetItemText(0, 4, Hik0.Number[i]);     //列表显示
            Hik0.List.SetItemText(0, 5, Hik0.Mac[i]);        //列表显示
            Hik0.List.SetItemText(0, 6, Hik0.NetIp[i]);      //列表显示
            Hik0.List.SetCheck(0, TRUE);			         //nItemOrder为行号
        } 
        //智能相机    
        Hik1.List.ModifyStyle(0, ~LVS_TYPEMASK &  LVS_EDITLABELS | LVS_REPORT, 0);
        Hik1.List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB | LVS_EX_DOUBLEBUFFER | LVS_EX_CHECKBOXES);  
        Hik1.List.InsertColumn(0, L"供包台ID", LVCFMT_LEFT, 60);//表头：1索引，2内容，3对齐方式，4宽度 
        Hik1.List.InsertColumn(1, L"设备IP", LVCFMT_LEFT, 100);
        Hik1.List.InsertColumn(2, L"型号", LVCFMT_LEFT, 80);
        Hik1.List.InsertColumn(3, L"版本号", LVCFMT_LEFT, 80);
        Hik1.List.InsertColumn(4, L"序列号", LVCFMT_LEFT, 90);
        Hik1.List.InsertColumn(5, L"物理地址", LVCFMT_LEFT, 90);
        Hik1.List.InsertColumn(6, L"网口IP", LVCFMT_LEFT, 100);
        for (int8_t i = Hik1.CheckNum - 1; i >= 0; --i)
        { 
            if (Hik1.Check[i] == false)continue;   //if (Hik1.Number[i] == "")continue;
            std::wstring wstrFeedId = std::to_wstring(Hik1.FeedId[i]);
            LPCWSTR lpFeedId = wstrFeedId.c_str();
            Hik1.List.InsertItem(0, lpFeedId);        //列表显示 
            Hik1.List.SetItemText(0, 1, Hik1.Ip[i]);        //列表显示
            Hik1.List.SetItemText(0, 2, Hik1.Name[i]);      //列表显示
            Hik1.List.SetItemText(0, 3, Hik1.Ves[i]);       //列表显示
            Hik1.List.SetItemText(0, 4, Hik1.Number[i]);    //列表显示
            Hik1.List.SetItemText(0, 5, Hik1.Mac[i]);       //列表显示
            Hik1.List.SetItemText(0, 6, Hik1.NetIp[i]);     //列表显示
            Hik1.List.SetCheck(0, TRUE);			        //nItemOrder为行号
        }
        //华睿智能相机 
        Dh1.List.ModifyStyle(0, ~LVS_TYPEMASK & LVS_EDITLABELS | LVS_REPORT, 0);
        Dh1.List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB | LVS_EX_DOUBLEBUFFER | LVS_EX_CHECKBOXES); 
        Dh1.List.InsertColumn(0, L"供包台ID", LVCFMT_LEFT, 60);//表头：1索引，2内容，3对齐方式，4宽度 
        Dh1.List.InsertColumn(1, L"设备IP", LVCFMT_LEFT, 100);
        Dh1.List.InsertColumn(2, L"型号", LVCFMT_LEFT, 80);
        Dh1.List.InsertColumn(3, L"版本号", LVCFMT_LEFT, 80);
        Dh1.List.InsertColumn(4, L"序列号", LVCFMT_LEFT, 90);
        Dh1.List.InsertColumn(5, L"物理地址", LVCFMT_LEFT, 90);
        Dh1.List.InsertColumn(6, L"网口IP", LVCFMT_LEFT, 100);
        for (int8_t i = Dh1.CheckNum - 1; i >= 0; --i)
        { 
            if (Dh1.Check[i] == false)continue;   //if (DaHua1.Number[i] == "")continue;
            std::wstring wstrFeedId = std::to_wstring(Dh1.FeedId[i]);
            LPCWSTR lpFeedId = wstrFeedId.c_str();
            Dh1.List.InsertItem(0, lpFeedId);     //列表显示 
            Dh1.List.SetItemText(0, 1, Dh1.Ip[i]);        //列表显示
            Dh1.List.SetItemText(0, 2, Dh1.Name[i]);      //列表显示
            Dh1.List.SetItemText(0, 3, Dh1.Ves[i]);       //列表显示
            Dh1.List.SetItemText(0, 4, Dh1.Number[i]);    //列表显示
            Dh1.List.SetItemText(0, 5, Dh1.Mac[i]);       //列表显示
            Dh1.List.SetItemText(0, 6, Dh1.NetIp[i]);     //列表显示
            Dh1.List.SetCheck(0, TRUE);                      //nItemOrder为行号
        } 
        //中科微至   
        Zw0.List.ModifyStyle(0, ~LVS_TYPEMASK & LVS_EDITLABELS | LVS_REPORT, 0);
        Zw0.List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB | LVS_EX_DOUBLEBUFFER | LVS_EX_CHECKBOXES); 
        Zw0.List.InsertColumn(0, L"供包台ID", LVCFMT_LEFT, 60);//表头：1索引，2内容，3对齐方式，4宽度 
        Zw0.List.InsertColumn(1, L"设备IP", LVCFMT_LEFT, 100);
        Zw0.List.InsertColumn(2, L"型号", LVCFMT_LEFT, 80);
        Zw0.List.InsertColumn(3, L"版本号", LVCFMT_LEFT, 80);
        Zw0.List.InsertColumn(4, L"序列号", LVCFMT_LEFT, 90);
        Zw0.List.InsertColumn(5, L"物理地址", LVCFMT_LEFT, 90);
        Zw0.List.InsertColumn(6, L"网口IP", LVCFMT_LEFT, 100);
        for (int8_t i = Zw0.CheckNum - 1; i >= 0; --i)
        {
            //CString strMsg;  strMsg.Format(L"---------显示------------------------%d----%d---%s：%d\r\n", i, i, Zw0.Ip[i], Zw0.Check[i]); OutputDebugString(strMsg);
            if (Zw0.Check[i] == false)continue;   //if (Zw0.Number[i] == "")continue;
            std::wstring wstrFeedId = std::to_wstring(Zw0.FeedId[i]);
            LPCWSTR lpFeedId = wstrFeedId.c_str(); 
            Zw0.List.InsertItem(0, lpFeedId);              //列表显示 
            Zw0.List.SetItemText(0, 1, Zw0.Ip[i]);         //列表显示
            Zw0.List.SetItemText(0, 2, Zw0.Name[i]);       //列表显示
            Zw0.List.SetItemText(0, 3, Zw0.Ves[i]);        //列表显示
            Zw0.List.SetItemText(0, 4, Zw0.Number[i]);     //列表显示
            Zw0.List.SetItemText(0, 5, Zw0.Mac[i]);        //列表显示
            Zw0.List.SetItemText(0, 6, Zw0.NetIp[i]);      //列表显示
            Zw0.List.SetCheck(0, TRUE);			           //nItemOrder为行号
        } 
    }
    return hbr;
} 
//读取配置文件
void DeviceList::GetConfig()
{
    CString CStr; CString KeyCstr;
    int MaxPath = 10240;                    //缓冲区大小 
    UINT8  DeviceNum = 0; // , n1 = 0;           //上一次扫描到的数量
    AppPath.Format(Oth.GetAppPath());
    ConfigPath.Format(L"%sSetting/Config.ini", AppPath.GetString());
    //海康工业相机
    KeyCstr = L"Hik0";
    GetPrivateProfileString(KeyCstr, _T("Type"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"DH-MV-S5600MG000;DH-MV-S5A20MG000;DH-MV-ESL5081M-00;DH-MV-S5B00MG000;R7250MG-00C-NGG01;R7201MG-00C-NGG01;R7200MG-00C-NGG01";
        WritePrivateProfileStringW(KeyCstr, _T("Type"), CStr, ConfigPath);  
    }
    Hik0.Type = CStr;    //支持的型号

    GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("LastNum"), CStr, ConfigPath); 
    }
    Hik0.LastNum = _ttoi(CStr);    //上一次扫描到的数量

    GetPrivateProfileString(KeyCstr, _T("CheckNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("CheckNum"), CStr, ConfigPath); 
    }
    Hik0.CheckNum = _ttoi(CStr);     //勾选数量  
    //n1 = 0;
    for (uint8_t i = 0; i < Hik0.CheckNum; i++)
    {
        CString KeyFeedId, KeyIp, KeyName, KeyVer, KeyNumber, KeyMac, KeyNetIp, KeyChcke, FeedId, Ip, Name, Ver, Number, Mac, NetIp, Chcke;
        KeyChcke.   Format(L"Checke%d",    i);
        KeyFeedId.  Format(L"FeedId%d",    i);
        KeyIp.      Format(L"Ip%d",        i);
        KeyName.    Format(L"Name%d",      i);
        KeyVer.     Format(L"Ver%d",       i);
        KeyNumber.  Format(L"Number%d",    i);
        KeyMac.     Format(L"Mac%d",       i);
        KeyNetIp.   Format(L"NetIp%d",     i);
        GetPrivateProfileString(KeyCstr, KeyChcke   , CString("NULL"), Chcke.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyFeedId  , CString("NULL"), FeedId.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyIp      , CString("NULL"), Ip.GetBuffer(MaxPath)    , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyName    , CString("NULL"), Name.GetBuffer(MaxPath)  , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyVer     , CString("NULL"), Ver.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNumber  , CString("NULL"), Number.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyMac     , CString("NULL"), Mac.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNetIp   , CString("NULL"), NetIp.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        if ( KeyChcke   == "" ||  KeyChcke   == "NULL"){ KeyChcke   = L"";  WritePrivateProfileStringW(KeyCstr,  KeyChcke  ,  Chcke  , ConfigPath);}
        if ( KeyFeedId  == "" ||  KeyFeedId  == "NULL"){ KeyFeedId  = L"";  WritePrivateProfileStringW(KeyCstr,  KeyFeedId ,  FeedId , ConfigPath);}
        if ( KeyIp      == "" ||  KeyIp      == "NULL"){ KeyIp      = L"";  WritePrivateProfileStringW(KeyCstr,  KeyIp     ,  Ip     , ConfigPath);}
        if ( KeyName    == "" ||  KeyName    == "NULL"){ KeyName    = L"";  WritePrivateProfileStringW(KeyCstr,  KeyName   ,  Name   , ConfigPath);}
        if ( KeyVer     == "" ||  KeyVer     == "NULL"){ KeyVer     = L"";  WritePrivateProfileStringW(KeyCstr,  KeyVer    ,  Ver    , ConfigPath);}
        if ( KeyNumber  == "" ||  KeyNumber  == "NULL"){ KeyNumber  = L"";  WritePrivateProfileStringW(KeyCstr,  KeyNumber ,  Number , ConfigPath);}
        if ( KeyMac     == "" ||  KeyMac     == "NULL"){ KeyMac     = L"";  WritePrivateProfileStringW(KeyCstr,  KeyMac    ,  Mac    , ConfigPath);}
        if ( KeyNetIp   == "" ||  KeyNetIp   == "NULL"){ KeyNetIp   = L"";  WritePrivateProfileStringW(KeyCstr,  KeyNetIp  ,  NetIp  , ConfigPath);}
        //Hik0.Check     [n1] = FALSE; if (Number == "") continue;     //是否已经勾选过  
        Hik0.Check     [i] = _ttoi(Chcke);
        if (Hik0.Check [i] == false)continue;
        Hik0.FeedId    [i] = _ttoi(FeedId); //供包台ID
        Hik0.Ip        [i] = Ip;            //IP
        Hik0.Ip_str    [i] = (CStringA)Ip;  //IP
        Hik0.Name      [i] = Name;          //型号
        Hik0.Ves       [i] = Ver;           //版本号  
        Hik0.Number    [i] = Number;        //序列号 
        Hik0.SN_str    [i] = (CStringA)Number; //序列号  
        Hik0.Mac       [i] = Mac;           //Mac 
        Hik0.NetIp     [i] = NetIp;         //网口IP 
        //n1++;
    }
    //海康智能相机
    KeyCstr = L"Hik1";
    GetPrivateProfileString(KeyCstr, _T("Type"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"";
        WritePrivateProfileStringW(KeyCstr, _T("Type"), CStr, ConfigPath);  
    }
    Hik1.Type = CStr;    //支持的型号

    GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("LastNum"), CStr, ConfigPath); 
    }
    Hik1.LastNum = _ttoi(CStr);    //上一次扫描到的数量

    GetPrivateProfileString(KeyCstr, _T("CheckNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("CheckNum"), CStr, ConfigPath); 
    }
    Hik1.CheckNum = _ttoi(CStr);     //勾选数量 
    //n1 = 0;
    for (uint8_t i = 0; i < Hik1.CheckNum; i++)
    {
        CString KeyFeedId, KeyIp, KeyName, KeyVer, KeyNumber, KeyMac, KeyNetIp, KeyChcke, FeedId, Ip, Name, Ver, Number, Mac, NetIp, Chcke;
        KeyChcke.   Format(L"Checke%d",     i);
        KeyFeedId.  Format(L"FeedId%d",    i);
        KeyIp.      Format(L"Ip%d",        i);
        KeyName.    Format(L"Name%d",      i);
        KeyVer.     Format(L"Ver%d",       i);
        KeyNumber.  Format(L"Number%d",    i);
        KeyMac.     Format(L"Mac%d",       i);
        KeyNetIp.   Format(L"NetIp%d",     i);
        GetPrivateProfileString(KeyCstr, KeyChcke   , CString("NULL"), Chcke.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyFeedId  , CString("NULL"), FeedId.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyIp      , CString("NULL"), Ip.GetBuffer(MaxPath)    , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyName    , CString("NULL"), Name.GetBuffer(MaxPath)  , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyVer     , CString("NULL"), Ver.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNumber  , CString("NULL"), Number.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyMac     , CString("NULL"), Mac.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNetIp   , CString("NULL"), NetIp.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        if ( KeyChcke   == "" ||  KeyChcke   == "NULL"){ KeyChcke   = L"";  WritePrivateProfileStringW(KeyCstr,  KeyChcke  ,  Chcke  , ConfigPath);}
        if ( KeyFeedId  == "" ||  KeyFeedId  == "NULL"){ KeyFeedId  = L"";  WritePrivateProfileStringW(KeyCstr,  KeyFeedId ,  FeedId , ConfigPath);}
        if ( KeyIp      == "" ||  KeyIp      == "NULL"){ KeyIp      = L"";  WritePrivateProfileStringW(KeyCstr,  KeyIp     ,  Ip     , ConfigPath);}
        if ( KeyName    == "" ||  KeyName    == "NULL"){ KeyName    = L"";  WritePrivateProfileStringW(KeyCstr,  KeyName   ,  Name   , ConfigPath);}
        if ( KeyVer     == "" ||  KeyVer     == "NULL"){ KeyVer     = L"";  WritePrivateProfileStringW(KeyCstr,  KeyVer    ,  Ver    , ConfigPath);}
        if ( KeyNumber  == "" ||  KeyNumber  == "NULL"){ KeyNumber  = L"";  WritePrivateProfileStringW(KeyCstr,  KeyNumber ,  Number , ConfigPath);}
        if ( KeyMac     == "" ||  KeyMac     == "NULL"){ KeyMac     = L"";  WritePrivateProfileStringW(KeyCstr,  KeyMac    ,  Mac    , ConfigPath);}
        if ( KeyNetIp   == "" ||  KeyNetIp   == "NULL"){ KeyNetIp   = L"";  WritePrivateProfileStringW(KeyCstr,  KeyNetIp  ,  NetIp  , ConfigPath);}
        //Hik1.Check    [n1] = FALSE; if (Number == "") continue;     //是否已经勾选过 
        Hik1.Check    [i] = _ttoi(Chcke);          //勾选
        if (Hik1.Check[i] == false)continue;
        Hik1.FeedId   [i] = _ttoi(FeedId);    //供包台ID
        Hik1.Ip       [i] = Ip;        //IP
        Hik1.Ip_str   [i] = (CStringA)Ip;  //IP
        Hik1.Name     [i] = Name;      //型号
        Hik1.Ves      [i] = Ver;       //版本号  
        Hik1.Number   [i] = Number;    //序列号 
        Hik1.SN_str   [i] = (CStringA)Number; //序列号   
        Hik1.Mac      [i] = Mac;       //Mac 
        Hik1.NetIp    [i] = NetIp;     //网口IP 
        //n1++; 
    }  
    //华睿智能相机
    KeyCstr = L"DaHua1";
    GetPrivateProfileString(KeyCstr, _T("Type"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"DH-MV-S5600MG000;DH-MV-S5A20MG000;DH-MV-ESL5081M-00;DH-MV-S5B00MG000;R7250MG-00C-NGG01;R7201MG-00C-NGG01;R7200MG-00C-NGG01";
        WritePrivateProfileStringW(KeyCstr, _T("Type"), CStr, ConfigPath);  
    }
    Dh1.Type = CStr;    //支持的型号

    GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("LastNum"), CStr, ConfigPath); 
    }
    Dh1.LastNum = _ttoi(CStr);    //上一次扫描到的数量

    GetPrivateProfileString(KeyCstr, _T("CheckNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("CheckNum"), CStr, ConfigPath); 
    }
    Dh1.CheckNum = _ttoi(CStr);     //勾选数量 
    //n1 = 0;
    for (uint8_t i = 0; i < Dh1.CheckNum; i++)
    {
        CString KeyFeedId, KeyIp, KeyName, KeyVer, KeyNumber, KeyMac, KeyNetIp, KeyChcke, FeedId, Ip, Name, Ver, Number, Mac, NetIp, Chcke;
        KeyChcke.   Format(L"Checke%d",     i);
        KeyFeedId.  Format(L"FeedId%d",    i);
        KeyIp.      Format(L"Ip%d",        i);
        KeyName.    Format(L"Name%d",      i);
        KeyVer.     Format(L"Ver%d",       i);
        KeyNumber.  Format(L"Number%d",    i);
        KeyMac.     Format(L"Mac%d",       i);
        KeyNetIp.   Format(L"NetIp%d",     i);
        GetPrivateProfileString(KeyCstr, KeyChcke   , CString("NULL"), Chcke.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyFeedId  , CString("NULL"), FeedId.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyIp      , CString("NULL"), Ip.GetBuffer(MaxPath)    , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyName    , CString("NULL"), Name.GetBuffer(MaxPath)  , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyVer     , CString("NULL"), Ver.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNumber  , CString("NULL"), Number.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyMac     , CString("NULL"), Mac.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNetIp   , CString("NULL"), NetIp.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        if ( KeyChcke   == "" || KeyChcke   == "NULL"){ KeyChcke  = L"";  WritePrivateProfileStringW(KeyCstr, KeyChcke , Chcke , ConfigPath);}
        if ( KeyFeedId  == "" || KeyFeedId  == "NULL"){ KeyFeedId = L"";  WritePrivateProfileStringW(KeyCstr, KeyFeedId, FeedId, ConfigPath);}
        if ( KeyIp      == "" || KeyIp      == "NULL"){ KeyIp     = L"";  WritePrivateProfileStringW(KeyCstr, KeyIp    , Ip    , ConfigPath);}
        if ( KeyName    == "" || KeyName    == "NULL"){ KeyName   = L"";  WritePrivateProfileStringW(KeyCstr, KeyName  , Name  , ConfigPath);}
        if ( KeyVer     == "" || KeyVer     == "NULL"){ KeyVer    = L"";  WritePrivateProfileStringW(KeyCstr, KeyVer   , Ver   , ConfigPath);}
        if ( KeyNumber  == "" || KeyNumber  == "NULL"){ KeyNumber = L"";  WritePrivateProfileStringW(KeyCstr, KeyNumber, Number, ConfigPath);}
        if ( KeyMac     == "" || KeyMac     == "NULL"){ KeyMac    = L"";  WritePrivateProfileStringW(KeyCstr, KeyMac   , Mac   , ConfigPath);}
        if ( KeyNetIp   == "" || KeyNetIp   == "NULL"){ KeyNetIp  = L"";  WritePrivateProfileStringW(KeyCstr, KeyNetIp , NetIp , ConfigPath);}
        //DaHua1.Check    [n1] = FALSE; if (Number == "") continue;     //是否已经勾选过 
        Dh1.Check    [i] = _ttoi(Chcke);          //勾选
        if (Dh1.Check[i] == false)continue;
        Dh1.FeedId   [i] = _ttoi(FeedId);    //供包台ID
        Dh1.Ip       [i] = Ip;        //IP
        Dh1.Ip_str   [i] = (CStringA)Ip;  //IP
        Dh1.Name     [i] = Name;      //型号
        Dh1.Ves      [i] = Ver;       //版本号  
        Dh1.Number   [i] = Number;    //序列号 
        Dh1.SN_str   [i] = (CStringA)Number; //序列号   
        Dh1.Mac      [i] = Mac;       //Mac 
        Dh1.NetIp    [i] = NetIp;     //网口IP 
        //n1++;
    }
    //中科微至
    KeyCstr = L"Zw0";
    GetPrivateProfileString(KeyCstr, _T("Type"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"";
        WritePrivateProfileStringW(KeyCstr, _T("Type"), CStr, ConfigPath);  
    }
    Zw0.Type = CStr;    //支持的型号

    GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("LastNum"), CStr, ConfigPath); 
    }
    Zw0.LastNum = _ttoi(CStr);    //上一次扫描到的数量

    GetPrivateProfileString(KeyCstr, _T("CheckNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath);
    if (CStr == "" || CStr == "NULL") {
        CStr = L"0";
        WritePrivateProfileStringW(KeyCstr, _T("CheckNum"), CStr, ConfigPath); 
    }
    Zw0.CheckNum = _ttoi(CStr);     //勾选数量 
    //n1 = 0;
    for (uint8_t i = 0; i < Zw0.CheckNum; i++)
    {
        CString KeyFeedId, KeyIp, KeyName, KeyVer, KeyNumber, KeyMac, KeyNetIp, KeyChcke, FeedId, Ip, Name, Ver, Number, Mac, NetIp, Chcke;
        KeyChcke.   Format(L"Checke%d",    i);
        KeyFeedId.  Format(L"FeedId%d",    i);
        KeyIp.      Format(L"Ip%d",        i);
        KeyName.    Format(L"Name%d",      i);
        KeyVer.     Format(L"Ver%d",       i);
        KeyNumber.  Format(L"Number%d",    i);
        KeyMac.     Format(L"Mac%d",       i);
        KeyNetIp.   Format(L"NetIp%d",     i);
        GetPrivateProfileString(KeyCstr, KeyChcke   , CString("NULL"), Chcke.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyFeedId  , CString("NULL"), FeedId.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyIp      , CString("NULL"), Ip.GetBuffer(MaxPath)    , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyName    , CString("NULL"), Name.GetBuffer(MaxPath)  , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyVer     , CString("NULL"), Ver.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNumber  , CString("NULL"), Number.GetBuffer(MaxPath), MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyMac     , CString("NULL"), Mac.GetBuffer(MaxPath)   , MaxPath, ConfigPath);
        GetPrivateProfileString(KeyCstr, KeyNetIp   , CString("NULL"), NetIp.GetBuffer(MaxPath) , MaxPath, ConfigPath);
        if ( KeyChcke   == "" ||  KeyChcke   == "NULL"){ KeyChcke   = L"";  WritePrivateProfileStringW(KeyCstr,  KeyChcke ,   Chcke  , ConfigPath);}
        if ( KeyFeedId  == "" ||  KeyFeedId  == "NULL"){ KeyFeedId  = L"";  WritePrivateProfileStringW(KeyCstr,  KeyFeedId ,  FeedId , ConfigPath);}
        if ( KeyIp      == "" ||  KeyIp      == "NULL"){ KeyIp      = L"";  WritePrivateProfileStringW(KeyCstr,  KeyIp     ,  Ip     , ConfigPath);}
        if ( KeyName    == "" ||  KeyName    == "NULL"){ KeyName    = L"";  WritePrivateProfileStringW(KeyCstr,  KeyName   ,  Name   , ConfigPath);}
        if ( KeyVer     == "" ||  KeyVer     == "NULL"){ KeyVer     = L"";  WritePrivateProfileStringW(KeyCstr,  KeyVer    ,  Ver    , ConfigPath);}
        if ( KeyNumber  == "" ||  KeyNumber  == "NULL"){ KeyNumber  = L"";  WritePrivateProfileStringW(KeyCstr,  KeyNumber ,  Number , ConfigPath);}
        if ( KeyMac     == "" ||  KeyMac     == "NULL"){ KeyMac     = L"";  WritePrivateProfileStringW(KeyCstr,  KeyMac    ,  Mac    , ConfigPath);}
        if ( KeyNetIp   == "" ||  KeyNetIp   == "NULL"){ KeyNetIp   = L"";  WritePrivateProfileStringW(KeyCstr,  KeyNetIp  ,  NetIp  , ConfigPath);}
        //Zw0.Check    [n1] = FALSE; if (Number == "") continue;     //是否已经勾选过 
        Zw0.Check    [i] = _ttoi(Chcke);
        if (Zw0.Check[i] == 0)continue;
        Zw0.FeedId   [i] = _ttoi(FeedId);    //供包台ID
        Zw0.Ip       [i] = Ip;        //IP
        Zw0.Ip_str   [i] = (CStringA)Ip;  //IP
        Zw0.Name     [i] = Name;      //型号
        Zw0.Ves      [i] = Ver;       //版本号   
        Zw0.Number   [i] = Number;    //序列号 
        Zw0.SN_str   [i] = (CStringA)Number; //序列号    
        Zw0.Mac      [i] = Mac;       //Mac 
        Zw0.NetIp    [i] = NetIp;     //网口IP 
        //CString strMsg;  strMsg.Format(L"---------读取------------------------%d----%d---%s：%d\r\n", i, i, Zw0.Ip[i], Zw0.Check[i]); OutputDebugString(strMsg);
        //n1++;
    }
    CStr.ReleaseBuffer();  //释放内存
}

//工业相机搜索
void DeviceList::BnClickedCamera0() 
{
    int ip   [MaxDeviceNum][4]{};   //相机IP 
    int netIp[MaxDeviceNum][4]{};   //IP   
    UINT8 n = 0;
    MVID_CAMERA_INFO_LIST* Dev0InfoList{};  
    Dev0InfoList = new MVID_CAMERA_INFO_LIST();  //初始化设备信息列表 | en:Device Information List Initialization 
    //if (NULL == Dev0InfoList) return;
    //memset(Dev0InfoList, 0, sizeof(MVID_CAMERA_INFO_LIST));
    int nRet = MVID_CR_CAM_EnumDevices(Dev0InfoList);
    if (MVID_CR_OK != nRet) return; 
    for (int8_t i = Hik0.List.GetItemCount() -1; i >= 0; i--)
    { 
        if (Hik0.List.GetCheck(i) == 0) //没勾选
        { 
            Hik0.List.DeleteItem(i); //根据索引删除
        } 
    }
    for (unsigned int i = 0; i < Dev0InfoList->nCamNum; i++)
    {
        MVID_CAMERA_INFO* pDeviceInfo = Dev0InfoList->pstCamInfo[i];
        if (NULL == pDeviceInfo) continue;
        char UserName[MaxDeviceNum] = { 0 };
        if (pDeviceInfo->nCamType == MVID_GIGE_CAM)
        {
            ip[i][0] = ((pDeviceInfo->nCurrentIp & 0xff000000) >> 24);
            ip[i][1] = ((pDeviceInfo->nCurrentIp & 0x00ff0000) >> 16);
            ip[i][2] = ((pDeviceInfo->nCurrentIp & 0x0000ff00) >> 8);
            ip[i][3] = ( pDeviceInfo->nCurrentIp & 0x000000ff);
            netIp[i][0] = ((pDeviceInfo->nNetExport & 0xff000000) >> 24);
            netIp[i][1] = ((pDeviceInfo->nNetExport & 0x00ff0000) >> 16);
            netIp[i][2] = ((pDeviceInfo->nNetExport & 0x0000ff00) >> 8);
            netIp[i][3] = (pDeviceInfo->nNetExport & 0x000000ff);
            wchar_t* pUserName = NULL;
            if (strcmp("", (LPCSTR)(pDeviceInfo->chUserDefinedName)) != 0)
            {
                DWORD dwLenUserName = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(pDeviceInfo->chUserDefinedName), -1, NULL, 0);
                pUserName = new wchar_t[dwLenUserName];
                MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(pDeviceInfo->chUserDefinedName), -1, pUserName, dwLenUserName);
            }
            else
            {
                //sprintf_s(UserName, "IP：    %d.%d.%d.%d\r\n型号：%s\r\n版本：%s", Ip[i][0], Ip[i][1], Ip[i][2], Ip[i][3], pDeviceInfo->chModelName, pDeviceInfo->chDeviceVersion);
                //DWORD dwLenUserName = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(UserName), -1, NULL, 0);
                //pUserName = new wchar_t[dwLenUserName];
                //MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(UserName), -1, pUserName, dwLenUserName);
            }
            int mac = pDeviceInfo->nMacAddrHigh << 16 | pDeviceInfo->nMacAddrLow;

            CString FeedId = L"1";
            CString Ip      ; Ip.Format(L"%d.%d.%d.%d", ip[i][0], ip[i][1], ip[i][2], ip[i][3]);
            CString Name    ; Name   = CStringW(pDeviceInfo->chModelName);
            CString Ver     ; Ver    = CStringW(pDeviceInfo->chDeviceVersion);
            CString Number  ; Number = CStringW(pDeviceInfo->chSerialNumber);
            CString Mac     ; Mac.Format(L"%X---", mac);
            CString NetIp   ; NetIp.Format(L"%d.%d.%d.%d", netIp[i][0], netIp[i][1], netIp[i][2], netIp[i][3]); 
            if (Name.Find(_T("PD")) < 0 && Name.Find(_T("MV-IDS")) < 0 && Name.Find(_T("IDS")) < 0)  //if (DaHua1.Type.Find(name) < 0)//MV-CH,MV-CA,MV-CE,MV-CB,MV-CL,MV-PD
                continue;   //排除其它型号 
            BOOL Redo = FALSE;
            for (int8_t j = Hik0.List.GetItemCount() - 1; j >= 0; j--)
            {
                if (Ip.Find(Hik0.List.GetItemText(j, 0)) >=0 && Hik0.List.GetCheck(j) == 1)
                {
                    Redo = TRUE; break;//判断是否勾选
                }
            }
            if (Redo == TRUE)continue; 
            n++;
            Hik0.Ip    [Hik0.CheckNum + n] = Ip;       //IP
            Hik0.Name  [Hik0.CheckNum + n] = Name;     //型号
            Hik0.Ves   [Hik0.CheckNum + n] = Ver;      //版本号 
            Hik0.Number[Hik0.CheckNum + n] = Number;   //序列号
            Hik0.Mac   [Hik0.CheckNum + n] = Mac;      //Mac
            Hik0.NetIp [Hik0.CheckNum + n] = NetIp;    //NetIp  
            //供包台ID读取
            std::map<CString, CString> mapNumber; //序列号, 供包台ID
            int MaxPath = 10240;
            CString KeyCstr = L"Hik0", CStr, KeyNumber, KeyFeedId, Number9, FeedId9;
            //GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath); 
            //uint8_t dev_num = _ttoi(CStr);     //上次搜到的数量 
            for (uint8_t nn = 0; nn < Hik0.LastNum; nn++)
            { 
                KeyNumber.Format(L"Number%d", nn);
                GetPrivateProfileString(KeyCstr, KeyNumber, CString("NULL"), Number9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

                KeyFeedId.Format(L"FeedId%d", nn);
                GetPrivateProfileString(KeyCstr, KeyFeedId, CString("NULL"), FeedId9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

                mapNumber.insert({ Number9, FeedId9 });
            }
            auto it_t = mapNumber.find(Number);
            if (it_t != mapNumber.end())
            {
                FeedId = mapNumber[Number];
            } 
            CStr.Format(L"%d", Dev0InfoList->nCamNum); WritePrivateProfileStringW(KeyCstr, L"LastNum", CStr, ConfigPath);  //获取扫描到的设备数
            Hik0.List.InsertItem (0,    FeedId);      //列表显示-ID
            Hik0.List.SetItemText(0, 1, Ip);          //列表显示-IP
            Hik0.List.SetItemText(0, 2, Name);        //列表显示-型号
            Hik0.List.SetItemText(0, 3, Ver);         //列表显示-版本号
            Hik0.List.SetItemText(0, 4, Number);      //列表显示-序列号
            Hik0.List.SetItemText(0, 5, Mac);         //列表显示-Mac
            Hik0.List.SetItemText(0, 6, NetIp);       //列表显示-网口IP
            if (NULL != pUserName)
            {
                delete[] pUserName;
                pUserName = NULL;
            }
        }
        else if (pDeviceInfo->nCamType == MVID_USB_CAM)
        {
            wchar_t* pUserName = NULL;
            if (strcmp("", (char*)pDeviceInfo->chUserDefinedName) != 0)
            {
                DWORD dwLenUserName = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(pDeviceInfo->chUserDefinedName), -1, NULL, 0);
                pUserName = new wchar_t[dwLenUserName];
                MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(pDeviceInfo->chUserDefinedName), -1, pUserName, dwLenUserName);
            }
            else
            {
                char strUserName[MaxDeviceNum];
                sprintf_s(strUserName, "%s %s (%s)", pDeviceInfo->chManufacturerName, pDeviceInfo->chModelName, pDeviceInfo->chSerialNumber);
                DWORD dwLenUserName = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(strUserName), -1, NULL, 0);
                pUserName = new wchar_t[dwLenUserName];
                MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(strUserName), -1, pUserName, dwLenUserName);
            }
            if (NULL != pUserName)
            {
                delete[] pUserName;
                pUserName = NULL;
            }
        }
        else
        {
            MessageBox(TEXT("未知设备枚举"), 0);
        }
    }
    //delete Dev0InfoList;  //待修
    UpdateData(FALSE);
}
//智能相机搜索
void DeviceList::BnClickedCamera1()
{
    USES_CONVERSION; 
    int nRet = MV_CODEREADER_OK;
    int ip[MaxDeviceNum][4]{};      //相机IP  
    int netIp[MaxDeviceNum][4]{};   //网口IP  
    UINT8 n = 0;
    // 查找设备
    memset(&Dev1InfoList, 0, sizeof(MV_CODEREADER_DEVICE_INFO_LIST));
    nRet = MV_CODEREADER_EnumDevices(&Dev1InfoList, MV_CODEREADER_GIGE_DEVICE);
    if (MV_CODEREADER_OK != nRet)   //枚举失败
    {
        return;
    }
    for (int8_t i = ((CListCtrl*)GetDlgItem(IDC_LIST1))->GetItemCount() - 1; i >= 0; i--)
    {
        if (((CListCtrl*)GetDlgItem(IDC_LIST1))->GetCheck(i) == 0) //没勾选
        {
            ((CListCtrl*)GetDlgItem(IDC_LIST1))->DeleteItem(i); //根据索引删除
        }
    }
    for (unsigned int i = 0; i < Dev1InfoList.nDeviceNum; i++)
    {
        ip[i][3] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nCurrentIp & 0xff);
        ip[i][2] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nCurrentIp & 0xff00) >> 8;
        ip[i][1] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nCurrentIp & 0xff0000) >> 16;
        ip[i][0] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24;  
        netIp[i][3] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nNetExport & 0xff);
        netIp[i][2] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nNetExport & 0xff00) >> 8;
        netIp[i][1] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nNetExport & 0xff0000) >> 16;
        netIp[i][0] = (Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.nNetExport & 0xff000000) >> 24;
        int mac = 0;

        CString FeedId = L"1";
        CString Ip      ; Ip.Format(L"%d.%d.%d.%d", ip[i][0], ip[i][1], ip[i][2], ip[i][3]);
        CString Name    ; Name   = CStringW(Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chModelName);           //型号
        CString Ver     ; Ver    = CStringW(Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chDeviceVersion);    //版本
        CString Number  ; Number = CStringW(Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber);      //序列号 
        CString Mac     ; Mac.Format(L"%X---", mac);
        CString NetIp   ; NetIp.Format(L"%d.%d.%d.%d", netIp[i][0], netIp[i][1], netIp[i][2], netIp[i][3]);
        if (Name.Find(_T("MV-IH")) < 0 && Name.Find(_T("MV-SI")) < 0 && Name.Find(_T("MV-IM")) < 0 && Name.Find(_T("MV-IL")) < 0 && Name.Find(_T("MV-ID")) < 0 && Name.Find(_T("MV-PD010003-21IH")) < 0 && Name.Find(_T("MV-PD010003-23IH")) < 0)  //if (DaHua1.Type.Find(name) < 0)//MV-CH,MV-CA,MV-CE,MV-CB,MV-CL,MV-PD
            continue;   //排除其它型号 
        BOOL Redo = FALSE;
        for (int8_t j = Hik1.List.GetItemCount() - 1; j >= 0; j--)
        {
            if (Ip.Find(Hik1.List.GetItemText(j, 0)) >= 0 && Hik1.List.GetCheck(j) == 1)
            {
                Redo = TRUE; break;//判断是否勾选
            }
        }
        if (Redo == TRUE)continue;
        n++;
        Hik1.Ip     [Hik1.CheckNum + n] = Ip;       //IP
        Hik1.Name   [Hik1.CheckNum + n] = Name;     //型号
        Hik1.Ves    [Hik1.CheckNum + n] = Ver;      //版本号 
        Hik1.Number [Hik1.CheckNum + n] = Number;   //序列号
        Hik1.Mac    [Hik1.CheckNum + n] = Mac;      //Mac
        Hik1.NetIp  [Hik1.CheckNum + n] = NetIp;    //NetIp 
        //供包台ID读取
        std::map<CString, CString> mapNumber; //序列号, 供包台ID
        int MaxPath = 10240;
        CString KeyCstr = L"Hik1", CStr, KeyNumber, KeyFeedId, Number9, FeedId9;
        //GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath); 
        //uint8_t dev_num = _ttoi(CStr);     //上次搜到的数量 
        for (uint8_t nn = 0; nn < Hik1.LastNum; nn++)
        { 
            KeyNumber.Format(L"Number%d", nn);
            GetPrivateProfileString(KeyCstr, KeyNumber, CString("NULL"), Number9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

            KeyFeedId.Format(L"FeedId%d", nn);
            GetPrivateProfileString(KeyCstr, KeyFeedId, CString("NULL"), FeedId9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

            mapNumber.insert({ Number9, FeedId9 });
        }
        auto it_t = mapNumber.find(Number);
        if (it_t != mapNumber.end())
        {
            FeedId = mapNumber[Number];
        }
        CStr.Format(L"%d", Dev1InfoList.nDeviceNum); WritePrivateProfileStringW(KeyCstr, L"LastNum", CStr, ConfigPath);  //获取扫描到的设备数
        Hik1.List.InsertItem(0, FeedId);          //列表显示-ID
        Hik1.List.SetItemText(0, 1, Ip);          //列表显示-IP
        Hik1.List.SetItemText(0, 2, Name);        //列表显示-型号
        Hik1.List.SetItemText(0, 3, Ver);         //列表显示-版本号
        Hik1.List.SetItemText(0, 4, Number);      //列表显示-序列号
        Hik1.List.SetItemText(0, 5, Mac);         //列表显示-Mac
        Hik1.List.SetItemText(0, 6, NetIp);       //列表显示-网口IP  
    }  
    UpdateData(FALSE);
}
//华睿智能相机                          
void DeviceList::OnBnClickedDahuacamera0()
{
    USES_CONVERSION;
    UINT8 n = 0;
    //华睿配置文件修改 
    tinyxml2::XMLDocument doc; const char* Emen{};
    doc.LoadFile(Oth.CStrToCh(Oth.GetAppPath() + L"Setting/LogisticsBase0.cfg"));
    if (doc.Error())
    {
        MessageBox(L"读取华睿相机xml文件失败 Load XML failed! ");
    }
    //1级节点
    tinyxml2::XMLElement* a1 = NULL;
    a1 = doc.RootElement(); 
    //2级节点
    tinyxml2::XMLElement* b1 = NULL; Emen = "ImageAcqCfg";
    if (a1 != NULL && a1->FirstChildElement(Emen) != NULL)
    {
        b1 = a1->FirstChildElement(Emen);
    }
    //3级节点
    tinyxml2::XMLElement* c1 = NULL;  Emen = "ImageAcq";
    if (b1 != NULL && b1->FirstChildElement(Emen) != NULL)
    {
        c1 = b1->FirstChildElement(Emen);
        c1->SetAttribute("mode", "1");   //重设值 1:自动发现相机 2:根据IP/Key发现相机
    }  
    doc.SaveFile(Oth.CStrToCh(Oth.GetAppPath() + L"Setting/LogisticsBase0.cfg"));
    //搜索华睿相机
    HuaRuiNum++; 
    int ret; CString str;
    if (h_HuaRui[HuaRuiNum] != NULL) {
        vslbDestroyBaseApp(h_HuaRui[HuaRuiNum]);   //销毁对象句柄 
    }
    h_HuaRui[HuaRuiNum] = vslbCreateBaseApp();     //创建对象句柄 
    if (h_HuaRui[HuaRuiNum] == NULL) {
        //MessageBox(L"1.创建对象句柄失败! App vslbCreateBaseApp failed!  ");
    }
    ret = vslbInitBaseApp(h_HuaRui[HuaRuiNum], Oth.CStrToCh(Oth.GetAppPath() + L"Setting/LogisticsBase0.cfg"));
    if (ret != 0) {
        //MessageBox(L"2.根据配置文件初始化对象句柄失败! App vslbInitBaseApp failed!  ");
    } 
    ret = vslbAttachAllCameraCodeinfoCB(h_HuaRui[HuaRuiNum], onListAllCameraCodeInfoC);
    if (ret != 0) {
        //MessageBox(L"4.注册所有相机的读码回调函数失败! App vslbAttachAllCameraCodeinfoCB failed!  ");
    }
    ret = vslbRun(h_HuaRui[HuaRuiNum], onRunResultCList);
    if (ret != 0) {
        str.Format(L"6.应用程序启动失败,取消当前勾选的相机后重启,错误码：%d! App run failed!  ", ret);
        //MessageBox(str);
    }
    //if (0 != vslbSoftTrigger(C3_handle));

#if defined _WIN64
    bool retb = vslbGetWorkCameraInfo(h_HuaRui[HuaRuiNum], onCameraInfosArray);
    if (!retb)
    {
        MessageBox(L"7.获取华睿智能相机信息列表失败!  ");
    }
    else
    {
        CString Num;
        Num.Format(L"%d", onCameraInfosArray->cameraNum);  //获取扫描到的设备数
        WritePrivateProfileStringW(L"DaHuaCamera", L"Device0Num", Num, ConfigPath);     
        for (int8_t i = ((CListCtrl*)GetDlgItem(IDC_DaHuaLIST0))->GetItemCount() - 1; i >= 0; i--)
        {
            if (((CListCtrl*)GetDlgItem(IDC_DaHuaLIST0))->GetCheck(i) == 0) //没勾选
            {
                ((CListCtrl*)GetDlgItem(IDC_DaHuaLIST0))->DeleteItem(i); //根据索引删除
            }
        }
        for (uint8_t i = 0; i < onCameraInfosArray->cameraNum; i++)
        {
            gCameraInfoMapTypeList[std::string(onCameraInfosArray->cameraInfos[i].camDevExtraInfo)] = onCameraInfosArray->cameraInfos[i];

            CString FeedId = L"1";
            CString Ip      ; Ip     = CStringW(onCameraInfosArray->cameraInfos[i].camDevExtraInfo);
            CString Name    ; Name   = CStringW(Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chModelName);       //型号
            CString Ver     ; Ver    = CStringW(Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chDeviceVersion);   //版本
            CString Number  ; Number = CStringW(Dev1InfoList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber);    //序列号 
            CString Mac     ;  
            CString NetIp   ; 
            //if (Name.Find(_T("ID")) < 0 || Name.Find(_T("TH")) < 0)  //if (DaHua1.Type.Find(name) < 0)//MV-CH,MV-CA,MV-CE,MV-CB,MV-CL,MV-PD
            //    continue;   //排除其它型号 
            BOOL Redo = FALSE;
            for (int8_t j = Dh1.List.GetItemCount() - 1; j >= 0; j--)
            {
                if (Ip.Find(Dh1.List.GetItemText(j, 0)) >= 0 && Dh1.List.GetCheck(j) == 1)
                {
                    Redo = TRUE; break;//判断是否勾选
                }
            }
            if (Redo == TRUE)continue;
            n++;
            Dh1.Ip[Hik1.CheckNum + n] = Ip;       //IP
            Dh1.Name[Hik1.CheckNum + n] = Name;     //型号
            Dh1.Ves[Hik1.CheckNum + n] = Ver;      //版本号 
            Dh1.Number[Hik1.CheckNum + n] = Number;   //序列号
            Dh1.Mac[Hik1.CheckNum + n] = Mac;      //Mac
            Dh1.NetIp[Hik1.CheckNum + n] = NetIp;    //NetIp 
            //供包台ID读取
            std::map<CString, CString> mapNumber; //序列号, 供包台ID
            int MaxPath = 10240;
            CString KeyCstr = L"DaHua1", CStr, KeyNumber, KeyFeedId, Number9, FeedId9;
            //GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath); 
            //uint8_t dev_num = _ttoi(CStr);     //上次搜到的数量 
            for (uint8_t nn = 0; nn < Dh1.LastNum; nn++)
            { 
                KeyNumber.Format(L"Number%d", nn);
                GetPrivateProfileString(KeyCstr, KeyNumber, CString("NULL"), Number9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

                KeyFeedId.Format(L"FeedId%d", nn);
                GetPrivateProfileString(KeyCstr, KeyFeedId, CString("NULL"), FeedId9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

                mapNumber.insert({ Number9, FeedId9 });
            }
            auto it_t = mapNumber.find(Number);
            if (it_t != mapNumber.end())
            {
                FeedId = mapNumber[Number];
            }
            CStr.Format(L"%d", onCameraInfosArray->cameraNum); WritePrivateProfileStringW(KeyCstr, L"LastNum", CStr, ConfigPath);  //获取扫描到的设备数
            Dh1.List.InsertItem(0, FeedId);          //列表显示-ID
            Dh1.List.SetItemText(0, 1, Ip);          //列表显示-IP
            Dh1.List.SetItemText(0, 2, Name);        //列表显示-型号
            Dh1.List.SetItemText(0, 3, Ver);         //列表显示-版本号
            Dh1.List.SetItemText(0, 4, Number);      //列表显示-序列号
            Dh1.List.SetItemText(0, 5, Mac);         //列表显示-Mac
            Dh1.List.SetItemText(0, 6, NetIp);       //列表显示-网口IP  

        }
    }
#endif  
    UpdateData(FALSE);
} 
//搜索-中科微至 
void DeviceList::zhong_wei_camera_infos(QuickScanSystemCameraInfoCpp* info, void* pUser)
{
    int ip[MaxDeviceNum][4]{};          //相机IP 
    int netIp[MaxDeviceNum][4]{};       //相机IP   
    UINT8 n = 0;
    for (int8_t i = ((CListCtrl*)GetDlgItem(IDC_ZhongWeiList0))->GetItemCount() - 1; i >= 0; i--)
    {
        if (((CListCtrl*)GetDlgItem(IDC_ZhongWeiList0))->GetCheck(i) == 0) //没勾选
        {
            ((CListCtrl*)GetDlgItem(IDC_ZhongWeiList0))->DeleteItem(i); //根据索引删除
        }
    }
    for (int i = 0; i < info->CameraCount; i++)
    {
        VersionInfoCpp version;
        QuickScanSdk_ResolveLibVersion(&version);     //获取版本号 
        CString FeedId = L"1";
        CString Ip      ; Ip     = CStringW(info->Cameras[i].CamIp);
        CString Name    ; Name   = CStringW(info->Cameras[i].CamFriendlyName);
        CString Ver     ; Ver    = CStringW(version.Version);
        CString Number  ; Number = CStringW(info->Cameras[i].CamSerialNumber);
        CString Mac     ; Mac    = CStringW(info->Cameras[i].EtMac);
        CString NetIp   ; NetIp  = CStringW(info->Cameras[i].EtIp);
        //if (Name.Find(_T("ID")) < 0 || Name.Find(_T("TH")) < 0)  //if (DaHua1.Type.Find(name) < 0)//MV-CH,MV-CA,MV-CE,MV-CB,MV-CL,MV-PD
        //    continue;   //排除其它型号 
        BOOL Redo = FALSE;
        for (int8_t j = Zw0.List.GetItemCount() - 1; j >= 0; j--)
        {
            if (Ip.Find(Zw0.List.GetItemText(j, 0)) >= 0 && Zw0.List.GetCheck(j) == 1)
            {
                Redo = TRUE; break;//判断是否勾选
            }
        }
        if (Redo == TRUE)continue;
        n++;
        Zw0.Ip     [Zw0.CheckNum + n] = Ip;       //IP
        Zw0.Name   [Zw0.CheckNum + n] = Name;     //型号
        Zw0.Ves    [Zw0.CheckNum + n] = Ver;      //版本号 
        Zw0.Number [Zw0.CheckNum + n] = Number;   //序列号
        Zw0.Mac    [Zw0.CheckNum + n] = Mac;      //Mac
        Zw0.NetIp  [Zw0.CheckNum + n] = NetIp;    //NetIp 
        //供包台ID读取
        std::map<CString, CString> mapNumber; //序列号, 供包台ID
        int MaxPath = 10240;
        CString KeyCstr = L"Zw0", CStr, KeyNumber, KeyFeedId, Number9, FeedId9;
        //GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath); 
        //uint8_t dev_num = _ttoi(CStr);     //上次搜到的数量 
        for (uint8_t nn = 0; nn < Zw0.LastNum; nn++)
        {
            KeyNumber.Format(L"Number%d", nn);
            GetPrivateProfileString(KeyCstr, KeyNumber, CString("NULL"), Number9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

            KeyFeedId.Format(L"FeedId%d", nn);
            GetPrivateProfileString(KeyCstr, KeyFeedId, CString("NULL"), FeedId9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

            mapNumber.insert({ Number9, FeedId9 });
        }
        auto it_t = mapNumber.find(Number);
        if (it_t != mapNumber.end())
        {
            FeedId = mapNumber[Number];
        }
        if (i == 0) { CStr.Format(L"%d", info->CameraCount); WritePrivateProfileStringW(KeyCstr, L"LastNum", CStr, ConfigPath); }  //获取扫描到的设备数
        Zw0.List.InsertItem(0, FeedId);          //列表显示-ID
        Zw0.List.SetItemText(0, 1, Ip);          //列表显示-IP
        Zw0.List.SetItemText(0, 2, Name);        //列表显示-型号
        Zw0.List.SetItemText(0, 3, Ver);         //列表显示-版本号
        Zw0.List.SetItemText(0, 4, Number);      //列表显示-序列号
        Zw0.List.SetItemText(0, 5, Mac);         //列表显示-Mac
        Zw0.List.SetItemText(0, 6, NetIp);       //列表显示-网口IP   
    }
}
void receive_camera_infos(QuickScanSystemCameraInfoCpp* info, void* pUser)
{
    DeviceList* pThis = (DeviceList*)pUser;
    if (pThis)
    {
        pThis->zhong_wei_camera_infos(info, pUser);
    }
} 
void DeviceList::OnBnClickedZhongweicamera0()
{ 
    QuickScanSystemCameraInfoCpp info;
    QuickScanStatus nRet = QUICK_SCAN_SUCCESS;
    nRet = QuickScanSdk_EnumerateAllQuickScanCameras(&info);
    if (nRet != QUICK_SCAN_SUCCESS)
    {
        static AtCodeMasterDlg* m_B = (AtCodeMasterDlg*)GetParent();
        m_B->print_a(5, "--搜索相机错误码(%#x)", nRet);
    }
    int ip[MaxDeviceNum][4]{};          //相机IP 
    int netIp[MaxDeviceNum][4]{};       //相机IP 
    UINT8 n = 0;
    for (int8_t i = ((CListCtrl*)GetDlgItem(IDC_ZhongWeiList0))->GetItemCount() - 1; i >= 0; i--)
    {
        if (((CListCtrl*)GetDlgItem(IDC_ZhongWeiList0))->GetCheck(i) == 0) //没勾选
        {
            ((CListCtrl*)GetDlgItem(IDC_ZhongWeiList0))->DeleteItem(i); //根据索引删除
        }
    }
    for (int i = 0; i < info.CameraCount; i++)
    {
        VersionInfoCpp version;
        QuickScanSdk_ResolveLibVersion(&version);     //获取版本号 
        CString FeedId = L"1";
        CString Ip; Ip = CStringW(info.Cameras[i].CamIp);
        CString Name; Name = CStringW(info.Cameras[i].CamFriendlyName);
        CString Ver; Ver = CStringW(version.Version);
        CString Number; Number = CStringW(info.Cameras[i].CamSerialNumber);
        CString Mac; Mac = CStringW(info.Cameras[i].EtMac);
        CString NetIp; NetIp = CStringW(info.Cameras[i].EtIp);
        //if (Name.Find(_T("ID")) < 0 || Name.Find(_T("TH")) < 0)  //if (DaHua1.Type.Find(name) < 0)//MV-CH,MV-CA,MV-CE,MV-CB,MV-CL,MV-PD
        //    continue;   //排除其它型号 
        BOOL Redo = FALSE;
        for (int8_t j = Zw0.List.GetItemCount() - 1; j >= 0; j--)
        {
            if (Ip.Find(Zw0.List.GetItemText(j, 0)) >= 0 && Zw0.List.GetCheck(j) == 1)
            {
                Redo = TRUE; break;//判断是否勾选
            }
        }
        if (Redo == TRUE)continue;
        n++;
        Zw0.Ip      [Zw0.CheckNum + n] = Ip;        //IP
        Zw0.Name    [Zw0.CheckNum + n] = Name;      //型号
        Zw0.Ves     [Zw0.CheckNum + n] = Ver;       //版本号
        Zw0.Number  [Zw0.CheckNum + n] = Number;    //序列号
        Zw0.Mac     [Zw0.CheckNum + n] = Mac;       //Mac
        Zw0.NetIp   [Zw0.CheckNum + n] = NetIp;     //NetIp 
        //供包台ID读取
        std::map<CString, CString> mapNumber; //序列号, 供包台ID
        int MaxPath = 10240;
        CString KeyCstr = L"Zw0", CStr, KeyNumber, KeyFeedId, Number9, FeedId9;
        //GetPrivateProfileString(KeyCstr, _T("LastNum"), CString("NULL"), CStr.GetBuffer(MaxPath), MaxPath, ConfigPath); 
        //uint8_t dev_num = _ttoi(CStr);     //上次搜到的数量 
        for (uint8_t nn = 0; nn < Zw0.LastNum; nn++)
        {
            KeyNumber.Format(L"Number%d", nn);
            GetPrivateProfileString(KeyCstr, KeyNumber, CString("NULL"), Number9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

            KeyFeedId.Format(L"FeedId%d", nn);
            GetPrivateProfileString(KeyCstr, KeyFeedId, CString("NULL"), FeedId9.GetBuffer(MaxPath), MaxPath, ConfigPath); 

            mapNumber.insert({ Number9, FeedId9 });
        }
        auto it_t = mapNumber.find(Number);
        if (it_t != mapNumber.end())
        {
            FeedId = mapNumber[Number];
        }
        if (i == 0) { CStr.Format(L"%d", info.CameraCount); WritePrivateProfileStringW(KeyCstr, L"LastNum", CStr, ConfigPath); }  //获取扫描到的设备数
        Zw0.List.InsertItem(0, FeedId);         //列表显示-ID
        Zw0.List.SetItemText(0, 1, Ip);         //列表显示-IP
        Zw0.List.SetItemText(0, 2, Name);       //列表显示-型号
        Zw0.List.SetItemText(0, 3, Ver);        //列表显示-版本号
        Zw0.List.SetItemText(0, 4, Number);     //列表显示-序列号
        Zw0.List.SetItemText(0, 5, Mac);        //列表显示-Mac
        Zw0.List.SetItemText(0, 6, NetIp);      //列表显示-网口IP   
    }
}
////值发生更改时-工业相机
//void DeviceList::OnLvnItemchangedList0(NMHDR* pNMHDR, LRESULT* pResult)
//{
//    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); 
//    *pResult = 0;
//}
////值发生更改时-智能相机
//void DeviceList::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
//{
//    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); 
//    *pResult = 0;
//}
////值发生更改时-华睿智能相机
//void DeviceList::OnLvnItemchangedDahualist0(NMHDR* pNMHDR, LRESULT* pResult)
//{ 
//    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); 
//    *pResult = 0;
//}
////值已更改-中科微至
//void DeviceList::OnLvnItemchangedZhongweilist0(NMHDR* pNMHDR, LRESULT* pResult)
//{
//    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); 
//    *pResult = 0;
//}
//  
void DeviceList::SetConfig()
{
    CString CStr, KeyCStr,CheckDev; UINT8 DevNum1 = 0; CString ValueCStr;
    CListCtrl* clist;
    for (int c = 0; c < 4; c++)
    {
        if (c == 0){ clist = (CListCtrl*)GetDlgItem(IDC_LIST0);         KeyCStr = L"Hik0";    }
        if (c == 1){ clist = (CListCtrl*)GetDlgItem(IDC_LIST1);         KeyCStr = L"Hik1";    }
        if (c == 2){ clist = (CListCtrl*)GetDlgItem(IDC_DaHuaLIST0);    KeyCStr = L"DaHua1";  }
        if (c == 3){ clist = (CListCtrl*)GetDlgItem(IDC_ZhongWeiList0); KeyCStr = L"Zw0";     }
        DevNum1 = 0;
        for (int i = 0; i < clist->GetItemCount(); i++)
        { 
            if (clist->GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED || clist->GetCheck(i))
            {
                CheckDev = L"1";
                CString FeedId = clist->GetItemText(i, 0);    //获取当前行的Id
                CString ip =     clist->GetItemText(i, 1);    //获取当前行的IP
                CString name =   clist->GetItemText(i, 2);    //获取当前行的型号
                CString ver =    clist->GetItemText(i, 3);    //获取当前行的版本号
                CString number = clist->GetItemText(i, 4);    //获取当前行的序列号
                CString mac =    clist->GetItemText(i, 5);    //获取当前行的MAC
                CString netip =  clist->GetItemText(i, 6);    //获取当前行的网口Ip
                ValueCStr.Format(L"Checke%d",  DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, CheckDev, ConfigPath);
                ValueCStr.Format(L"FeedId%d",  DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 0), ConfigPath);  
                ValueCStr.Format(L"Ip%d",      DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 1), ConfigPath);  
                ValueCStr.Format(L"Name%d",    DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 2), ConfigPath);  
                ValueCStr.Format(L"Ver%d",     DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 3), ConfigPath);  
                ValueCStr.Format(L"Number%d",  DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 4), ConfigPath);  
                ValueCStr.Format(L"Mac%d",     DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 5), ConfigPath);  
                ValueCStr.Format(L"NetIp%d",   DevNum1); WritePrivateProfileStringW(KeyCStr, ValueCStr, clist->GetItemText(i, 6), ConfigPath);
                CString strMsg;  strMsg.Format(L"---------写入------------------------%d----%d---%s：%s\r\n", DevNum1, i, clist->GetItemText(i, 1), CheckDev); OutputDebugString(strMsg);

                if (c == 2)
                {
                    //华睿配置文件修改 
                    CString cstr; cstr.Format(L"%sSetting/LogisticsBase0.cfg", Oth.GetAppPath().GetString());
                    tinyxml2::XMLDocument doc; const char* Emen{};
                    doc.LoadFile(Oth.CStrToCh(cstr));
                    if (doc.Error())
                    {
                        MessageBox(L"华睿相机读取xml文件失败 Load XML failed! ");
                    }
                    //1级节点
                    tinyxml2::XMLElement* a1 = NULL;
                    a1 = doc.RootElement();
                    //2级节点
                    tinyxml2::XMLElement* b1 = NULL; Emen = "ImageAcqCfg";
                    if (a1 != NULL && a1->FirstChildElement(Emen) != NULL)
                    {
                        b1 = a1->FirstChildElement(Emen);
                    }
                    //3级节点
                    tinyxml2::XMLElement* c1 = NULL;  Emen = "ImageAcq";
                    if (b1 != NULL && b1->FirstChildElement(Emen) != NULL)
                    {
                        c1 = b1->FirstChildElement(Emen);
                        c1->SetAttribute("mode", "2");   //重设值 1:自动发现相机 2:根据IP/Key发现相机
                        CString CamNum;
                        CamNum.Format(L"%d", DevNum1);                      //获取选中的设备数  
                        c1->SetAttribute("num", Oth.CStrToCh(CamNum));
                    }
                    //3级节点-0
                    tinyxml2::XMLElement* c2a0 = NULL;  Emen = "Camera";
                    if (b1 != NULL && b1->FirstChildElement(Emen) != NULL && i == 0)
                    {
                        c2a0 = b1->FirstChildElement(Emen)->NextSiblingElement();
                        c2a0->SetAttribute("enable", "0");
                        c2a0 = b1->FirstChildElement(Emen)->NextSiblingElement()->NextSiblingElement();
                        c2a0->SetAttribute("enable", "0");
                        c2a0 = b1->FirstChildElement(Emen)->NextSiblingElement()->NextSiblingElement()->NextSiblingElement();
                        c2a0->SetAttribute("enable", "0");
                        c2a0 = b1->FirstChildElement(Emen)->NextSiblingElement()->NextSiblingElement()->NextSiblingElement()->NextSiblingElement();
                        c2a0->SetAttribute("enable", "0");

                        c2a0 = b1->FirstChildElement(Emen)->NextSiblingElement();
                        c2a0->SetAttribute("key", Oth.CStrToCh(number));   //重设值  
                        c2a0->SetAttribute("enable", "1");
                    }
                    //3级节点-1
                    tinyxml2::XMLElement* c2a1 = NULL;  Emen = "Camera";
                    if (b1 != NULL && b1->FirstChildElement(Emen) != NULL && i == 1)
                    {
                        c2a1 = b1->FirstChildElement(Emen)->NextSiblingElement()->NextSiblingElement();
                        c2a1->SetAttribute("key", Oth.CStrToCh(number));   //重设值  
                        c2a1->SetAttribute("enable", "1");
                    }
                    //3级节点-2
                    tinyxml2::XMLElement* c2a2 = NULL;  Emen = "Camera";
                    if (b1 != NULL && b1->FirstChildElement(Emen) != NULL && i == 2)
                    {
                        c2a2 = b1->FirstChildElement(Emen)->NextSiblingElement()->NextSiblingElement()->NextSiblingElement();
                        c2a2->SetAttribute("key", Oth.CStrToCh(number));   //重设值  
                        c2a2->SetAttribute("enable", "1");
                    }
                    //3级节点-3
                    tinyxml2::XMLElement* c2a3 = NULL;  Emen = "Camera";
                    if (b1 != NULL && b1->FirstChildElement(Emen) != NULL && i == 3)
                    {
                        c2a3 = b1->FirstChildElement(Emen)->NextSiblingElement()->NextSiblingElement()->NextSiblingElement()->NextSiblingElement();
                        c2a3->SetAttribute("key", Oth.CStrToCh(number));   //重设值  
                        c2a3->SetAttribute("enable", "1");
                    }
                    doc.SaveFile(Oth.CStrToCh(cstr));//保存华睿配置文件
                }
                DevNum1++;
            }
            else
            {
                ValueCStr.Format(L"Checke%d", i); WritePrivateProfileStringW(KeyCStr, ValueCStr, CheckDev, ConfigPath);
                //ValueCStr.Format(L"FeedId%d", i); WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
                //ValueCStr.Format(L"Ip%d", i);     WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
                //ValueCStr.Format(L"Name%d", i);   WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
                //ValueCStr.Format(L"Ver%d", i);    WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
                //ValueCStr.Format(L"Number%d", i); WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
                //ValueCStr.Format(L"Mac%d", i);    WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
                //ValueCStr.Format(L"NetIp%d", i);  WritePrivateProfileStringW(KeyCStr, ValueCStr, L"", ConfigPath);
            }
        }
        //CStr.Format(L"%d", clist->GetItemCount());    //获取扫描到的设备数
        //WritePrivateProfileStringW(KeyCStr, L"LastNum", CStr, ConfigPath);   

        CStr.Format(L"%d", DevNum1);                     //获取选中的设备数 
        WritePrivateProfileStringW(KeyCStr, L"CheckNum", CStr, ConfigPath);
    }
}

//窗口即将销毁
void DeviceList::OnDestroy()
{
    CDialogEx::OnDestroy(); 
    SetConfig();       
    GetConfig();    //读取配置文件 
    if (Dh1.CheckNum > 0)    //关闭华睿相机
    {
        int ret;
        delete(onCameraInfosArray);
        for (int i = 0; i < HuaRuiNum; i++)
        {
            if (h_HuaRui[i] == NULL)continue;
            ret = vslbDetachAllCameraCodeinfoCB(h_HuaRui[i], onListAllCameraCodeInfoC);
            if (ret < 0)
            {
                CloseHandle(h_HuaRui[i]);
                //MessageBox(L"取消所有相机的读码回调函数失败! App vslbAttachAllCameraCodeinfoCB failed!  ");
                continue;
            }
            ret = vslbStop(h_HuaRui[i]);
            if (ret < 0)
            {
                CloseHandle(h_HuaRui[i]);
                //MessageBox(L"停止vslbStop失败 App vslbStop failed.  ");
                continue;
            }
            ret = vslbFiniBaseApp(h_HuaRui[i]);
            if (ret < 0)
            {
                CloseHandle(h_HuaRui[i]);
                //MessageBox(L"反初始化失败 App vslbFiniBaseApp failed.  ");
                continue;
            }
            vslbDestroyBaseApp(h_HuaRui[i]);
        }
    }
    //AtovoCodeMasterDlg* m_B = (AtovoCodeMasterDlg*)GetParent();
    //m_B->GetConfig();             //主窗体更新配置参数     
    //m_B->CreateWindowHandle(0);   //创建图像显示窗口句柄 
    //m_B->Reconnect();             //相机重连   
    ListOne = FALSE;
}

////完成项标签的编辑-海康相机0
//void DeviceList::OnLvnEndlabeleditList0(NMHDR* pNMHDR, LRESULT* pResult)
//{
//    NMLVDISPINFO* pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
//    CString newText = pDispInfo->item.pszText; // 获取编辑后的文本  
//    int nColumn = pDispInfo->item.iSubItem;
//    int nRow = pDispInfo->item.iItem;
//    CListCtrl* Hik0List = (CListCtrl*)GetDlgItem(IDC_LIST0);
//
//    CStringArray itemTexts;
//    for (int i = 0; i < Hik0List->GetHeaderCtrl()->GetItemCount(); ++i)  // 获取当前行的所有列数据  
//    {
//        CString text = Hik0List->GetItemText(i, nRow);    //获取当前行的ID
//        itemTexts.Add(text);
//    }
//    itemTexts.SetAt(nColumn, newText);
//    Hik0List->SetItemText(nRow, nColumn, newText);// 仅更新特定列的数据  
//    *pResult = 0;
//}
////完成项标签的编辑-海康智能相机
//void DeviceList::OnLvnEndlabeleditList1(NMHDR* pNMHDR, LRESULT* pResult)
//{
//    NMLVDISPINFO* pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
//    CString newText = pDispInfo->item.pszText; // 获取编辑后的文本  
//    int nColumn = pDispInfo->item.iSubItem;
//    int nRow = pDispInfo->item.iItem;
//    CListCtrl* Hik1List = (CListCtrl*)GetDlgItem(IDC_LIST1);
//
//    CStringArray itemTexts;
//    for (int i = 0; i < Hik1List->GetHeaderCtrl()->GetItemCount(); ++i)  // 获取当前行的所有列数据  
//    {
//        CString text = Hik1List->GetItemText(i, nRow);    //获取当前行的ID
//        itemTexts.Add(text);
//    }
//    itemTexts.SetAt(nColumn, newText);
//    Hik1List->SetItemText(nRow, nColumn, newText);// 仅更新特定列的数据 
//    *pResult = 0;
//}
////完成项标签的编辑-中科微至相机
//void DeviceList::OnLvnEndlabeleditZhongweilist0(NMHDR* pNMHDR, LRESULT* pResult)
//{
//    NMLVDISPINFO* pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
//    CString newText = pDispInfo->item.pszText; // 获取编辑后的文本  
//    int nColumn = pDispInfo->item.iSubItem;
//    int nRow = pDispInfo->item.iItem;
//    CListCtrl* Zw0List = (CListCtrl*)GetDlgItem(IDC_ZhongWeiList0);
//
//    CStringArray itemTexts;
//    for (int i = 0; i < Zw0List->GetHeaderCtrl()->GetItemCount(); ++i)  // 获取当前行的所有列数据  
//    {
//        CString text = Zw0List->GetItemText(i, nRow);    //获取当前行的ID
//        itemTexts.Add(text);
//    }
//    itemTexts.SetAt(nColumn, newText);
//    Zw0List->SetItemText(nRow, nColumn, newText);// 仅更新特定列的数据 
//    *pResult = 0;
//}

void DeviceList::OnBnClickedCameraipconfigs()
{
    CString FilePath; FilePath.Format(L"%sCameraIpConfigs.cfg", Oth.GetAppPath().GetString()); 
    ShellExecute(NULL, L"open", FilePath, NULL, NULL, SW_SHOWNORMAL);
}

//编辑框丢失焦点
int m_Row; int m_Col;
void DeviceList::OnEnKillfocusEdit1Cameralisthik0()
{
    CString tem;
    EditHik0.GetWindowText(tem); //得到用户输入的新的内容
    Hik0.List.SetItemText(m_Row, m_Col, tem); //设置编辑框的新内容
    EditHik0.ShowWindow(SW_HIDE); //隐藏编辑框 
}
void DeviceList::OnEnKillfocusEdit1Cameralisthik1()
{
    CString tem;
    EditHik1.GetWindowText(tem); //得到用户输入的新的内容
    Hik1.List.SetItemText(m_Row, m_Col, tem); //设置编辑框的新内容
    EditHik1.ShowWindow(SW_HIDE); //隐藏编辑框 
}
void DeviceList::OnEnKillfocusEdit1Cameralistdh1()
{
    CString tem;
    EditDh1.GetWindowText(tem); //得到用户输入的新的内容
    Dh1.List.SetItemText(m_Row, m_Col, tem); //设置编辑框的新内容
    EditDh1.ShowWindow(SW_HIDE); //隐藏编辑框 
}
void DeviceList::OnEnKillfocusEdit1Cameralistzw0()
{
    CString tem;
    EditZw0.GetWindowText(tem); //得到用户输入的新的内容
    Zw0.List.SetItemText(m_Row, m_Col, tem); //设置编辑框的新内容
    EditZw0.ShowWindow(SW_HIDE); //隐藏编辑框 
} 
//海康工业相机-左键点击
void DeviceList::OnNMDblclkList0(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    CRect rc;
    CListCtrl* ListPrint1 = (CListCtrl*)GetDlgItem(IDC_LIST0);
    m_Row = pNMListView->iItem;     //获得选中的行
    m_Col = pNMListView->iSubItem;  //获得选中列
    int n = ListPrint1->GetItemCount(); //获取当前一共多少行
    if (pNMListView->iSubItem < 20)     //如果选择的是子项;
    {
        ListPrint1->GetSubItemRect(m_Row, m_Col, LVIR_LABEL, rc);//获得子项的RECT；
        EditHik0.SetParent(ListPrint1);   //转换坐标为列表框中的坐标
        EditHik0.MoveWindow(rc);           //移动Edit到RECT坐在的位置;
        EditHik0.SetWindowText(ListPrint1->GetItemText(m_Row, m_Col)); //将该子项中的值放在Edit控件中；
        EditHik0.ShowWindow(SW_SHOW);  //显示Edit控件；
        EditHik0.SetFocus();   //设置Edit焦点
        EditHik0.ShowCaret();  //显示光标
        EditHik0.SetSel(-1);   //将光标移动到最后
        if (m_Row == n - 1)  ListPrint1->InsertItem(m_Row + 1, _T(""));
    }
    *pResult = 0;
} 
//海康智能相机-左键点击
void DeviceList::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    CRect rc;
    m_Row = pNMListView->iItem;     //获得选中的行
    m_Col = pNMListView->iSubItem;  //获得选中列
    int n = Hik1.List.GetItemCount();   //获取当前一共多少行
    if (pNMListView->iSubItem < 20)     //如果选择的是子项;
    {
        Hik1.List.GetSubItemRect(m_Row, m_Col, LVIR_LABEL, rc);//获得子项的RECT；
        EditHik1.SetParent(&Hik1.List);     //转换坐标为列表框中的坐标
        EditHik1.MoveWindow(rc);            //移动Edit到RECT坐在的位置;
        EditHik1.SetWindowText(Hik1.List.GetItemText(m_Row, m_Col)); //将该子项中的值放在Edit控件中；
        EditHik1.ShowWindow(SW_SHOW);  //显示Edit控件；
        EditHik1.SetFocus();   //设置Edit焦点
        EditHik1.ShowCaret();  //显示光标
        EditHik1.SetSel(-1);   //将光标移动到最后
        if (m_Row == n - 1)  Hik1.List.InsertItem(m_Row + 1, _T(""));
    }
    *pResult = 0;
}
//中科微至工业相机-左键点击
void DeviceList::OnNMDblclkZhongweilist0(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    CRect rc;
    CListCtrl* ListPrint1 = (CListCtrl*)GetDlgItem(IDC_ZhongWeiList0);
    m_Row = pNMListView->iItem;     //获得选中的行
    m_Col = pNMListView->iSubItem;  //获得选中列
    int n = ListPrint1->GetItemCount(); //获取当前一共多少行
    if (pNMListView->iSubItem < 20)     //如果选择的是子项;
    {
        ListPrint1->GetSubItemRect(m_Row, m_Col, LVIR_LABEL, rc);//获得子项的RECT；
        EditZw0.SetParent(ListPrint1);   //转换坐标为列表框中的坐标
        EditZw0.MoveWindow(rc);           //移动Edit到RECT坐在的位置;
        EditZw0.SetWindowText(ListPrint1->GetItemText(m_Row, m_Col)); //将该子项中的值放在Edit控件中；
        EditZw0.ShowWindow(SW_SHOW);  //显示Edit控件；
        EditZw0.SetFocus();   //设置Edit焦点
        EditZw0.ShowCaret();  //显示光标
        EditZw0.SetSel(-1);   //将光标移动到最后
        if (m_Row == n - 1)  ListPrint1->InsertItem(m_Row + 1, _T(""));
    }
    *pResult = 0;
}
